import type { MessageData } from '../../../../shares/sharesApp';
import { ClientEvents } from '../../../../shares/sharesApp';
import { Singleton } from '../../framework/common/Singleton';
import { RemoteMgr } from './remoteMgr';
import { Message } from '../entity/message';
import i18n from '../../../../i18n';
import { I18nMgr } from './i18nMgr';

/**
 * 消息管理器 / Message manager
 */
export class MessageMgr extends Singleton<MessageMgr>() {
    constructor() {
        super();
        console.log('(Client) MeassageMgr constructor');
    }

    start(): void {
        this.bindEvents();
    }

    bindEvents(): void {
        RemoteMgr.instance.onClientEvent((event) => {
            switch (event.type) {
                case ClientEvents.MESSAGE:
                    const data = event.data as MessageData;
                    new Message(I18nMgr.t(data.contentKey, data?.params));
                    break;
            }
        });
    }
}
